介面之間可以互有繼承關係,亦即使用承接自父介面(super interface)的子介面(sub interface)來創建物件。
interface Named {
val name: String
}
interface Person : Named {
val firstName: String
val lastName: String
override val name: String get() = "$firstName $lastName"
}
data class Employee(
// implementing 'name' is not required
override val firstName: String,
override val lastName: String,
val position: Position
) : Person
既有的介面 | 衍伸出的介面 |
---|---|
父介面(super interface) | 子介面(sub interface) |
基底介面(basis interface) | 衍生介面(derived interface) |